# IterativeTree.py # # Description: Draws a tree iteratively (i.e., using a loop). # # Author: Alenjandra Jahns and AL # Last Modification Date: March 4 2024 # Import the turtle and the random libraries import turtle import random # Define a function that draws leaves def drawLeaf(aTurtle, aColour): '''Draws a leaf ietratively where "aTurtle" is the turtle drawing the tree and "aColour" is the colour of the leaf. ''' aTurtle.color(aColour) aTurtle.penup() # Positioning the turtle at a random location aTurtle.goto(random.randint(-170,170), random.randint(0,250)) aTurtle.pendown() # Drawing a "leaf" of a random size aTurtle.dot(random.randint(10,50)) return # ***Main part of my program # Creates a graphics window "canvas" canvas = turtle.Screen() canvas.bgcolor("lightblue") # Create a turtle named "tt" tt = turtle.Turtle() # Set up our turtle "tt" tt.width(30) # Move our turtle "tt" tt.speed(0) tt.penup() tt.goto(0, -180) tt.left(90) tt.pendown() # Draw the trunk theTrunkLength = 180 tt.forward(theTrunkLength) # Determine the number of leaves to draw numberOfLeaves = random.randint(50,300) # Call our function for eachLeaf in range(numberOfLeaves): drawLeaf(tt, "green") # Click on the canvas to exit canvas.exitonclick()